#!/usr/bin/env python
# coding: utf-8

# In[4]:


def legal_func_name(s_func):
    not_alnum_ = any([not (ch.isalnum() or '_'==ch)  for ch in s_func])
    s0 = s_func[0]
    not_begin_right = not( s0.isalpha() or s0=='_' )
    return not( not_alnum_ or not_begin_right )

def reverse_snt(snt):
    words = snt.split()
    words_reversed = words[::-1]
    return ' '.join(words_reversed)


    
   


# In[6]:


def print_shoppinglist():
    width = 30
    price_width = 10
    item_width = width - price_width
    
    header_format = '%-*s%*s'
    format = '%-*s%*.2f'
    
    print('='*width) 
#打印表头
    print(header_format %(item_width,'项目',price_width,'价格'))
    
    print('-' * width)
    
    print(format % (item_width,'苹果',price_width,6.0))
    print(format % (item_width,'桔子',price_width,3.2))
    print(format % (item_width,'香蕉',price_width,2.5))
    print(format % (item_width,'葡萄',price_width,14.8))
    print(format % (item_width,'红提',price_width,15))
    print(format % (item_width,'西瓜',price_width,1.5))

    print('='*width)

import math
def print_1_2N_acc(N):
    formu_res_arr = []
    for i in range(1,N+1):
        formu = [ '1/{}'.format(str(2**j) if j<=4 else '2^'+str(j)) for j in range(1,i+1)]
        res = [ 1/math.pow(2,j) for j in range(1,i+1)]
        formu_res =  "{} = {}".format( '+'.join(formu), sum(res) )
        formu_res_arr.append(formu_res)
    print('\n'.join(formu_res_arr))


def fib_loop_for(n):
    a, b = 0, 1
    for _ in range(n):
        a, b = b, a + b
    return a

def fibonacci_spiral_len(n):
    for i in range(1,n+1):
        acc_fib_ = [ fib_loop_for(j) for j in range(0, i) ]
        acc_fib = [ fib_loop_for(j) for j in range(0, i+1)]
        if i>1:
            print(sum(acc_fib_),'\t',sum(acc_fib),'\t',sum(acc_fib)/sum(acc_fib_))
        else:
            print(sum(acc_fib_),'\t',sum(acc_fib),'\t','-')    

if __name__=='__main__':
    # print_shoppinglist()
    # print_1_2N_acc(20)
    fibonacci_spiral_len(50)
#好家伙，为啥出来这一堆数字


# In[11]:


#拉倒了，换个试试
items = [('苹果',6.00),('桔子',3.20),('香蕉',2.50),('葡萄',14.80),('红提',15.00),('西瓜',1.50)]
print(f"{'='*30}\n{'商品':<13s}{'价格':>13s}\n{'-'*30}")
for item, price in items:
    print(f"{item:<13s}{price:>13.2f}")
#好家伙，一顿调试才调出来好看的格式


# In[ ]:




